package com.crr.controller;

import cn.hutool.core.bean.BeanUtil;
import com.crr.common.bean.PageBean;
import com.crr.common.bean.ResultBean;
import com.crr.common.controller.BaseController;
import com.crr.query.UserQuery;
import com.crr.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * @Api(tags = "用户管理")  tags更改说明
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/v1")
public class UserController extends BaseController {
    @Autowired
    UserService userService;
    @ApiImplicitParam(name = "account" ,paramType = "query", value = "用户名", dataTypeClass = String.class, required = true)
    @GetMapping("/user/check")
    @ApiOperation("用户唯一检查")
   public ResultBean checkUser(@RequestParam(name="account",required = true) String account){
      int res= userService.queryUserByAccount(account);
      String tem=res==1?"no":"yes";
      return success("账号唯一检查",tem);
   }
   @ApiOperation("查询用户列表")
   @PostMapping("/user/query")
   public ResultBean query( @RequestBody UserQuery userQuery,BindingResult result){
       PageBean bean = userService.query(BeanUtil.beanToMap(userQuery));
       return success("查询列表",bean);
   }

}
